//
//  BindingBootcamp_23.swift
//  SwiftUiExercise
//
//  Created by 徐鹏 on 2023/7/1.
//

import SwiftUI

struct BindingBootcamp_23: View {
    
    @State var backgroundColor :Color = Color.green
    @State var title: String = "Title"
    
    var body: some View {
        ZStack{
            backgroundColor
                .edgesIgnoringSafeArea(.all)
            
            VStack {
                Text(title)
                    .foregroundColor(.white)
                ButtonView(backgroudColor: $backgroundColor,title: $title)
            }
           

        }
    }
}


struct ButtonView: View{
    
    @Binding var backgroudColor: Color
    @Binding var title: String
    @State   var buttonColor: Color = Color.blue
    
    var body: some View {
        Button {
            backgroudColor = Color.orange
            buttonColor = Color.pink
            title = "NEW Title ........."
        } label: {
            Text("Button")
                .foregroundColor(.white)
                .padding()
                .padding(.horizontal)
                .background(buttonColor)
                .cornerRadius(10)
        }
    }
}

struct BindingBootcamp_23_Previews: PreviewProvider {
    static var previews: some View {
        BindingBootcamp_23()
    }
}
